
/**
 * The Enemy class creates an Enemy object that extends MovableEnt
 * 
 * @author      Zachary Bellido
 * @version     0.01
 */

import java.awt.*;
import java.awt.geom.*;

public class Enemy extends MovableEnt implements StepInterface
{

    /**
     * Constructor for objects of class Enemy
     */
    public Enemy(char symbol, int coordX, int coordY)
    {
        // initialise instance variables
        super(symbol, coordX, coordY);
        Grid.addEnt(this);
    }

     /**
     * Preform actions every timer tick
     * 
     * @pre     object must be initialized     
     * @param   none
     * @return  none
     * @post    none    
     */
    public void step(){
        //Only move 2 out of 3 steps.
        stepInterval++;
        if (stepInterval % 3 == 0)
            stepInterval = 0;
        else{
            int distX = Runner.player.getCoordX() - this.getCoordX();
            int distY = Runner.player.getCoordY() - this.getCoordY();
            int moveX = 0;
            int moveY = 0;
            //Check which direction player is in.
            if (Math.abs(distX) > 0)
                moveX = distX / Math.abs(distX);
            if (Math.abs(distY) > 0)
                moveY = distY / Math.abs(distY);
            //Hurt nearby players.
            if(Math.abs(distX) <= 1 && Math.abs(distY) <= 1)
            {
                Runner.player.decreaseHealth(10);
            }
            //Move.
            moveRestricted(moveX, moveY);
        }
    }
    
}

